<template>
  <div class="user">
    <!-- 登录状态 -->
    <template v-if="token">
      <div class="user-poster">
        <p>欢迎</p>
      </div>
      <van-row class="user-links">
        <van-col span="6"> <van-icon name="pending-payment" />待付款 </van-col>
        <van-col span="6"> <van-icon name="records" />待接单 </van-col>
        <van-col span="6"> <van-icon name="tosend" />待发货 </van-col>
        <van-col span="6"> <van-icon name="logistics" />已发货 </van-col>
      </van-row>

      <van-cell-group class="user-group">
        <van-cell icon="records" title="地址管理" is-link />
      </van-cell-group>

      <van-cell-group>
        <van-cell icon="points" title="我的积分" is-link />
        <van-cell icon="gold-coin-o" title="我的优惠券" is-link />
        <van-cell icon="gift-o" title="我收到的礼物" is-link />
      </van-cell-group>

      <van-button type="danger" size="large">退出账号</van-button>
    </template>

    <!-- 没登录状态 -->
    <template v-else>
      <div class="noUserInfo">
        <van-button
          class="register"
          type="primary"
          size="mini"
          @click="toRegister"
          >注册</van-button
        >
        <p>
          已有账号?
          <router-link to="/login">登录</router-link>
        </p>
      </div>
    </template>

    <tab-bar></tab-bar>
  </div>
</template>



<script>
import { getInfo } from "../../apis/user";
export default {
  data() {
    return {
      token: false,
    };
  },
  methods: {
    toRegister() {
      this.$router.push("/register");
    },
  },
  async activated() {
    if (this.$getStorage("jwtToken")) {
      this.token = true;
      let res = await this.$http.request({
        url: getInfo,
        method: "POST",
      });
      console.log(res);
    }
  },
};
</script>

<style>
.user {
  height: 100%;
  padding-bottom: 50px;
}
.user-poster {
  width: 100%;
  height: 53vw;
  display: block;
  background: yellowgreen;
}
.user-poster p {
  text-align: center;
  height: inherit;
  line-height: 53vw;
}
.user-group {
  margin-bottom: 15px;
}
.user-links {
  padding: 15px 0;
  font-size: 12px;
  text-align: center;
  background-color: #fff;
}
.van-icon {
  display: block;
  font-size: 24px;
}
.noUserInfo {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  width: 100%;
  height: 50px;
  text-align: center;
}
</style>